import { DatabaseSource } from './Types';
import { Dao } from '../schema/Dao';
import { Database } from '../schema/Database';
import { relationalStore } from '@kit.ArkData';

/**
 * 数据库的基类
 */
export abstract class BaseDatabase {
  protected constructor(private readonly database: DatabaseSource) {
  }

  /**
   * 从数据源中获取原始的 RdbStore
   *
   * @returns RdbStore
   */
  protected get rdbStore(): relationalStore.RdbStore {
    if (this.database instanceof Database) {
      return this.database.rdbStore
    }
    if (this.database instanceof Dao) {
      return this.database.database.rdbStore
    }
    return this.database
  }
}